var TOOLBAR_QUOTE = 1;
var TOOLBAR_FUND = 2;


function createToolBar(divParent, type)
{
	var htmlObject;
	var divElements = "elements_"+divParent;

	var imagesPath = "http://investmentmonitor.googlecode.com/svn/trunk/resources/img/";

	htmlObject = document.createElement('div');
	htmlObject.id = divElements;
	htmlObject.style.display = "block";
	_gel(divParent).appendChild(htmlObject);

	htmlObject = document.createElement('hr');
	htmlObject.size = "1";
	htmlObject.width = "100%";
	_gel(divParent).appendChild(htmlObject);

	createToolbarHeader__MODULE_ID__(divElements,imagesPath);
	
	switch(type)
	{
		case TOOLBAR_QUOTE:
			createInvestmentQuoteForm__MODULE_ID__(divElements,imagesPath);
			break;
		case TOOLBAR_FUND:
			//createInvestmentFundForm__MODULE_ID__("toolbar__MODULE_ID__",imagesPath);
			break;
	}
}

function createToolbarHeader__MODULE_ID__(parent, imgPath)
 {
	var htmlObject = document.createElement('div');
 	var htmlCode = "<div id='toolbarHeader__MODULE_ID__' style='display: block'>";

	htmlCode += "<table cellspacing='0'>";
	htmlCode += "<tr>";
  	htmlCode += "  <td >";
 	htmlCode += "    <img style='cursor: pointer' src='"+imgPath+"addInvestment.gif' border='0' onclick='javascript:showInvestmentForm__MODULE_ID__();' style='text-decoration:none; font-size: 12px; color: black;' />";
  	htmlCode += "    </td>";
	htmlCode += "  <td >";
 	htmlCode += "    <img style='cursor: pointer' src='"+imgPath+"config.gif' border='0' onclick='javascript:showInvestmentForm__MODULE_ID__();' style='text-decoration:none; font-size: 12px; color: black;' />";
  	htmlCode += "    </td>";
  	htmlCode += "  <td style='width:100%;text-align:right'></td>";
  	htmlCode += "  <td>";
  	htmlCode += "    <img src='"+imgPath+"about.gif' style='cursor: pointer' onclick='javascript:openAbout__MODULE_ID__();'  border='0'/>";
  	htmlCode += "  </td>";
  	htmlCode += "  <td>";
  	htmlCode += "    <img src='"+imgPath+"help.gif' style='cursor: pointer' onclick='javascript:openHelp__MODULE_ID__();'  border='0'/>";
  	htmlCode += "  </td>";
  	htmlCode += "</tr>";
  	htmlCode += "</table>";
  	htmlCode += "</div>";

  	htmlObject.innerHTML = htmlCode;
  	_gel(parent).appendChild(htmlObject);


}

function createInvestmentQuoteForm__MODULE_ID__(parent, imgPath)
{
	var htmlObject = document.createElement('div');
	var htmlCode = "<div id='investmentForm__MODULE_ID__' class='investmentForm' style='display:none;font-size:85%'>";

	htmlCode += "<div>";
	htmlCode += "<IMG src='" + imgPath + "close.gif' onclick='javascript: saveInvestments__MODULE_ID__();' style='cursor:pointer;margin:3px' align='right' height='10' width='10' >";
	htmlCode += "<p style='font-weight:bold;text-align:left;font-size:110%'> Add Investments Data</p>";
	htmlCode += "    <br/>";
	htmlCode += "    <table  style='width:100%'>";
	htmlCode += "      <tr>";
	htmlCode += "        <td  style='width:5%'>";
	htmlCode += "          <nobr>Quote Symbol:</nobr>";
	htmlCode += "        </td>";
	htmlCode += "        <td style='text-align:left'>";
	htmlCode += "          <input id='newQuote__MODULE_ID__' type='text' style='width:25;height:20'>";
	htmlCode += "        </td>";
	htmlCode += "        <td  style='width:5%;text-align:right'>";
	htmlCode += "          <img src='"+imgPath+"add.gif' height='14' width='14' style='cursor: pointer' onclick='javascript: addToInvestmentForm__MODULE_ID__();'  border='0'/>";
	htmlCode += "        </td>";
	htmlCode += "        <td  style='width:5%;text-align:right'>";
	htmlCode += "          <img src='"+imgPath+"locate.gif'  height='14' width='14' style='cursor: pointer' onclick='javascript: showSearchResults__MODULE_ID__();'  border='0'/>";
	htmlCode += "        </td>";
	htmlCode += "        <td style='width:100%;text-align:right'></td>";
	htmlCode += "    </tr>";
	htmlCode += "   </table>";
	htmlCode += "</div>";
	htmlCode += "<br/>";

	htmlCode += "<div id='searchResultBox__MODULE_ID__' class='searchResultBox'  style='display:none;'>";
	htmlCode += "<IMG src='" + imgPath + "close.gif' onclick='javascript: closeSearchResults__MODULE_ID__();' style='cursor:pointer;margin:3px' align='right' height='10' width='10' >";
	htmlCode += "<p style='font-weight:bold;text-align:left;font-size:110%;'> Quote Symbol Lookup</p>";
	htmlCode += "    <br/>";
	htmlCode += " <table cellspacing='3' style='width:100%'>";
	htmlCode += "   <tr style='font-weight:bold'>";
	htmlCode += "      <td nowrap='nowrap' width='20%'>Symbol</td>";
	htmlCode += "      <td  nowrap='nowrap' width='50%'>Name</td>";
	htmlCode += "      <td  nowrap='nowrap' width='25%'>Exchange</td>";
	htmlCode += "      <td nowrap='nowrap' width='5%'></td>";
	htmlCode += "  </tr>";
	htmlCode += "  <tr style='height: 1px; background-color: rgb(188, 188, 188);'>";
	htmlCode += "      <td colspan='4'></td>";
	htmlCode += "  </tr>";
	htmlCode += "   <tr>";
	htmlCode += "     <td  id='ctc00'  nowrap='nowrap'>GOOG</td>";
	htmlCode += "     <td  id='ctc00'  nowrap='nowrap'>GOOGLE INC.</td>";
	htmlCode += "     <td  id='ctc00'  nowrap='nowrap'>USA</td>";
	htmlCode += "     <td><img src='" + imgPath + "add.gif'  style='cursor: pointer' border='0' height='10' width='10'/> </td>";
	htmlCode += "   </tr>";
	htmlCode += "   <tr>";
	htmlCode += "     <td id='ctc00'  nowrap='nowrap'>GOOG</td>";
	htmlCode += "     <td  id='ctc00'  nowrap='nowrap'>GOOGLE INC.</td>";
	htmlCode += "     <td  id='ctc00'  nowrap='nowrap'>USA</td>";
	htmlCode += "     <td><img src='" + imgPath + "checked.gif'  border='0' height='10' width='10'/> </td>";
	htmlCode += "   </tr>";
	htmlCode += "</table>";
	htmlCode += "</div>";

	htmlCode += "<div style='display:block'>";
	htmlCode += "<table cellspacing='3' style='width:100%'>";
	htmlCode += "<tr style='font-weight:bold'>";
	htmlCode += "<td nowrap='nowrap' width='30%'>Symbol</td>";
	htmlCode += "<td  nowrap='nowrap' width='40%'>Date</td>";
	htmlCode += "<td  nowrap='nowrap' width='15%'>Price</td>";
	htmlCode += "<td  nowrap='nowrap' width='15%'>Qty.</td>";
	htmlCode += "<td  nowrap='nowrap' ></td>";
	htmlCode += "</tr>";
	htmlCode += "<tr style='height: 1px; background-color: rgb(188, 188, 188);'>";
	htmlCode += "   <td colspan='5'></td>";
	htmlCode += "</tr>";
	htmlCode += "<tr style='align-text:left'>";
	htmlCode += " <td  id='ctc00' title='Click to change this item' onclick='editInvestmentField(this)' onmouseover='setOverColor(this,true);' onmouseout='setOverColor(this,false);' nowrap='nowrap'>GOOG</td>";
	htmlCode += " <td  id='ctc00' title='Click to change this item' onclick='editInvestmentField(this)' onmouseover='setOverColor(this,true);' onmouseout='setOverColor(this,false);' nowrap='nowrap'>20/05/2007</td>";
	htmlCode += " <td  id='ctc10' title='Click to change this item' onclick='editInvestmentField(this)' onmouseover='setOverColor(this,true);' onmouseout='setOverColor(this,false);' nowrap='nowrap'>0</td>";
	htmlCode += " <td  id='ctc20' title='Click to change this item' onclick='editInvestmentField(this)' onmouseover='setOverColor(this,true);' onmouseout='setOverColor(this,false);' nowrap='nowrap'>0</td>";
	htmlCode += "  <td align='right' nowrap='nowrap' width='25'><img src='"+imgPath+"delete.gif' id='ctc30' style='cursor: pointer;' onclick='fnDeleteStock(0)'  title='Remove' height='10' width='10'></td>";
	htmlCode += "</tr>";
	htmlCode += "<tr>";
	htmlCode += " <td  id='ctc00' title='Click to change this item' onclick='editInvestmentField(this)' onmouseover='setOverColor(this,true);' onmouseout='setOverColor(this,false);' nowrap='nowrap'>GOOG</td>";
	htmlCode += " <td  id='ctc00' title='Click to change this item' onclick='editInvestmentField(this)' onmouseover='setOverColor(this,true);' onmouseout='setOverColor(this,false);' nowrap='nowrap'>20/05/2007</td>";
	htmlCode += " <td  id='ctc10' title='Click to change this item' onclick='editInvestmentField(this)' onmouseover='setOverColor(this,true);' onmouseout='setOverColor(this,false);' nowrap='nowrap'>0</td>";
	htmlCode += " <td  id='ctc20' title='Click to change this item' onclick='editInvestmentField(this)' onmouseover='setOverColor(this,true);' onmouseout='setOverColor(this,false);' nowrap='nowrap'>0</td>";
	htmlCode += "  <td align='right' nowrap='nowrap' width='25'><img src='"+imgPath+"delete.gif' id='ctc30' style='cursor: pointer;' onclick='fnDeleteStock(0)'  title='Remove' height='10' width='10'></td>";
	htmlCode += "</tr>";

	htmlCode += "</table>";
	htmlCode += "</div>";

	htmlCode += "</div>";

	htmlObject.innerHTML = htmlCode;
  	_gel(parent).appendChild(htmlObject);

}

function showInvestmentForm__MODULE_ID__()
{

	var elements = new Array("investmentForm__MODULE_ID__","toolbarHeader__MODULE_ID__");
	toggleElements(elements);
}

function addToInvestmentForm__MODULE_ID__()
{
	//toggleLayer('addSymbolForm__MODULE_ID__');
}




function openHelp__MODULE_ID__()
{
	var path = "http://gadgets.joshuakent.com/bookmarks/help.html";
	window.open('+path+','myWindow','menubar=0,resizable=1,scrollbars=0,width=450,height=400');
}

function openAbout__MODULE_ID__()
{
	var path = "http://gadgets.joshuakent.com/bookmarks/about.html";
	window.open('+path+','myWindow','menubar=0,resizable=1,scrollbars=0,width=450,height=400');
}

function saveInvestments__MODULE_ID__()
{
	var elements = new Array("investmentForm__MODULE_ID__","toolbarHeader__MODULE_ID__");
	toggleElements(elements);
}



function showSearchResults__MODULE_ID__(){
  var elements = new Array("searchResultBox__MODULE_ID__");
	toggleElements(elements);
}


function closeSearchResults__MODULE_ID__(){
  var elements = new Array("searchResultBox__MODULE_ID__");
	toggleElements(elements);
}



function editInvestmentField(sender)
{
	if(sender.innerHTML.toLowerCase().indexOf("input",1)>0)
		{
			return;
		}
	var sTemp=sender.innerHTML;
	var b=document.createElement("INPUT");
	b.id="txtTempInput";
	b.style.fontSize=sender.style.fontSize;
	b.style.fontFamily="sans-serif";
	b.style.textAlign='left';
	b.style.width=sender.style.width;
	b.style.height="15px";
	b.style.margin="0px";
	//b.onblur=onBlurField;
	sender.innerHTML="";
	sender.appendChild(b);
	b.focus();
	b.value=sTemp;
	b.select();
}



function onBlurField(sender)
{
	var index=sender.id.substr(4);
	var col=sender.id.substr(3,1);
	if((col==0&&trim(b.value)!="")||!isNaN(b.value))
	{
		if(col==0)
		{
			arrStocksymbols[index]=b.value;
		}
		else
		if(col==1)
		{
			arrStockPrices[index]=b.value;
		}
		else
		if(col==2)
		{
			arrStockQtys[index]=b.value;
		}

		fnSavePrefs();
		fnUpdateStocks();
	}
	fnInsertAdd();
}

/*function fnInsertAdd()
{
	var sTemp='<hr class="HrDef"><table border=0 id="tblTickers" cellspacing=0 cellpadding=0 style="font-size:'+fsize+'" class="def"><tr><td width="62px" align="left"><input type="text" autocomplete="on" style="font-size:'+fsize+';width:60px" bclass="def" id="txtStockSymbol" name="txtStockSymbol" alt="Symbol" title="Enter symbol or company name" value=""></td><td width="20px" align="left"><img width="12" height="12" style="cursor:hand;cursor:pointer;" onclick="var Temp=_gel(\'txtStockSymbol\').value;fnAddStock(Temp);" title="Add" src="'+_IG_GetImage('http://cnybroe.googlepages.com/AddStock.gif').src+'"></td><td width="45px"><select id="cbSearch" style="font-size:'+fsize+';width:80px;" class="def"><option selected value="S">Stocks</option><option value="E">ETFs</option><option value="I">Indices</option><option value="M">Mutual Funds</option><option value="F">Futures</option></select></td><td width="20px" align="middle"><img width="16" height="16" border=0 style="cursor:hand;cursor:pointer;" onclick="fnSymbolSearch()" src="'+_IG_GetImage('http://cnybroe.googlepages.com/symbollookup.gif').src+'" title="Lookup"></img></td><td></td></tr></table><div id="StockAddList" style="font-size:'+fsize+'" class="def"></div>';var sLine='<tr style="height:1px;background-Color:BCBCBC"><td colspan=6></td></tr>';
	var sConfigTable='<table width="100%" border=0 cellspacing=0 cellpadding=0 style="font-size:'+fsize+'" class="def"><tr style="height:3px"><td colspan=6></td></tr>'+sLine+'<tr style="font-weight: bold;"><td nowrap width="50%">Symbol</td><td nowrap align="right" width="20%">Price</td><td nowrap align="right" width="20%">Qty.</td><td colspan=3></td></tr>'+sLine;
	for(i=0;i<arrStocksymbols.length;i++)
	{
		sConfigTable+='<tr><td id="ctc0'+i+'" title="Click to change this item" onclick="fnEditStock(this)" onmouseover=this.style.backgroundColor="#dcdcdc" onmouseout=this.style.backgroundColor="#FFFFFF" nowrap>'+arrStocksymbols[i]+'</td><td id="ctc1'+i+'" title="Click to change this item" onclick="fnEditStock(this)" onmouseover=this.style.backgroundColor="#dcdcdc" onmouseout=this.style.backgroundColor="#FFFFFF" nowrap align="right">'+arrStockPrices[i]+'</td><td id="ctc2'+i+'" title="Click to change this item" onclick="fnEditStock(this)" onmouseover=this.style.backgroundColor="#dcdcdc" onmouseout=this.style.backgroundColor="#FFFFFF" nowrap align="right">'+arrStockQtys[i]+'</td><td nowrap align="right" width="25px"><img id="ctc3'+i+'" width="10" height="10" style="cursor:hand;cursor:pointer;" onclick="fnDeleteStock('+i+')" src="'+_IG_GetImage('http://cnybroe.googlepages.com/delete.gif').src+'" title="Remove"></td><td nowrap align="right" width="15px"><img id="ctc4'+i+'" width="10" height="10" style="cursor:hand;cursor:pointer;" onclick="fnMoveStock('+i+',0)" src="'+_IG_GetImage('http://cnybroe.googlepages.com/MoveUp.gif').src+'" title="Move up"></td><td nowrap align="right" width="15px"><img id="ctc5'+i+'" width="10" height="10" style="cursor:hand;cursor:pointer;" onclick="fnMoveStock('+i+',1)" src="'+_IG_GetImage('http://cnybroe.googlepages.com/MoveDown.gif').src+'" title="Move down"></td></tr>';
	}
	sConfigTable+='</table>';_gel("StockAdd").innerHTML=sTemp+sConfigTable;}
}*/

function setOverColor(sender,isOver)
{
	if(isOver)
		sender.style.backgroundColor="#cceebb";
	else
		sender.style.backgroundColor="#ddffcc";

}





